// packageA/pages/orderSystem/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        statusList: [
            { id: 'all', name: '全部订单' },
            { id: 'completed', name: '已完成' },
            { id: 'pending', name: '待付款' },
            { id: 'paid', name: '待发货' },
            { id: 'shipped', name: '待收货' },
            { id: 'after_sale', name: '售后中' },
            { id: 'closed', name: '已关闭' }
          ],
          shopIndex: 0,
          shopList: [
            { name: '全部门店', value: 'all' },
            { name: '南山店', value: 'nanshan' },
            { name: '福田店', value: 'futian' },
            { name: '龙华店', value: 'longhua' }
          ],
          currentStatus: { id: 'all', name: '全部订单' },
          currentDate: '',
          orderNo: '',
          orderList: [
            {
              id: '1',
              orderNo: 'NO202309210001',
              goodsImage: 'https://picsum.photos/200/200?random=1',
              goodsName: '经典奶皮子酸奶',
              spec: '500g*2盒',
              amount: '56.00',
              status: 'pending',
              statusText: '待付款',
              createTime: '2023-09-21 10:30:25'
            },
            {
              id: '2',
              orderNo: 'NO202309200002',
              goodsImage: 'https://picsum.photos/200/200?random=2',
              goodsName: '蓝莓奶皮子酸奶',
              spec: '500g*1盒',
              amount: '32.00',
              status: 'paid',
              statusText: '待发货',
              createTime: '2023-09-20 15:12:43'
            },
            {
              id: '3',
              orderNo: 'NO202309190003',
              goodsImage: 'https://picsum.photos/200/200?random=3',
              goodsName: '原味奶皮子酸奶',
              spec: '500g*3盒',
              amount: '78.00',
              status: 'shipped',
              statusText: '待收货',
              createTime: '2023-09-19 09:45:12'
            }
          ]
    },
    shopChange(e) {
        this.setData({ shopIndex: e.detail.value })
        this.loadData()
      },
// 状态筛选变化
handleStatusChange(e) {
    const index = e.detail.value
    this.setData({
      currentStatus: this.data.statusList[index]
    })
    this.filterOrders()
  },

  // 订单编号输入
  handleOrderNoInput(e) {
    this.setData({
      orderNo: e.detail.value
    })
    this.filterOrders()
  },

  // 日期选择变化
  handleDateChange(e) {
    this.setData({
      currentDate: e.detail.value
    })
    this.filterOrders()
  },

  // 筛选订单
  filterOrders() {
    // 实际项目中这里应该是请求接口获取筛选后的订单
    console.log('筛选条件:', {
      status: this.data.currentStatus.id,
      orderNo: this.data.orderNo,
      date: this.data.currentDate
    })
  },

  // 查看订单详情
  viewDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/packageA/pages/order-detail/index?id=${id}`
    })
  },

  // 查看物流
  viewLogistics(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/packageA/pages/delivery-progress/index?id=${id}`
    })
  },

  // 发货操作
  shipOrder(e) {
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '确认发货',
      content: '确定要发货吗？',
      success: (res) => {
        if (res.confirm) {
          // 实际项目中这里调用发货接口
          wx.showToast({
            title: '发货成功',
            icon: 'success'
          })
        }
      }
    })
  },

  // 取消订单
  cancelOrder(e) {
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '取消订单',
      content: '确定要取消该订单吗？',
      success: (res) => {
        if (res.confirm) {
          // 实际项目中这里调用取消订单接口
          wx.showToast({
            title: '订单已取消',
            icon: 'success'
          })
        }
      }
    })
  },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})